package hub.cathome.controller;

import hub.cathome.entity.Comment;
import hub.cathome.entity.ShotBlog;
import hub.cathome.entity.User;
import hub.cathome.service.CommentService;
import hub.cathome.service.ShotBlogService;
import hub.cathome.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class CommentController {
    @Resource(name="commentService")
    private CommentService commentService;
    @Resource(name="shotBlogService")
    private ShotBlogService shotBlogService;
    @RequestMapping("/affair/shotBlog/comment")
    public void commentShotBlog(@RequestParam("blogId") Integer blogId,@RequestParam("content") String content, HttpSession session, HttpServletRequest request){
        User user = (User) session.getAttribute("user");
        Comment comment = new Comment();
        comment.setContent(content);
        comment.setDate(new Date());
        comment.setShotBlogId(blogId);
        comment.setUser(user);
        commentService.insertComment(comment);
    }

}
